using System;
using System.Collections;
using System.Web;
using System.Web.SessionState;
using Sedna.Core.Common;

namespace Sedna.Core.Controller.Menu
{
	public class LeftMenuAwareActionParam : IActionParam
	{
		public string Name
		{
			get { return "menu_level_2"; }
			set { throw new NotSupportedException(); }
		}

		public string GetValue(IExecutionContext executionContext)
		{
			string menuLevel2 = (string)executionContext["menu_level_2"];
			if(menuLevel2 == null)
			{
                menuLevel2 = MenuUtils.ExtractMenuLevel2Param(executionContext);
			}
			if(menuLevel2 == null || menuLevel2 == string.Empty)
			{
                menuLevel2 = ExtractFromSession(executionContext);
			}
			return menuLevel2;
		}

        private string ExtractFromSession(IExecutionContext executionContext)
		{
			return (string)executionContext.GetScopedValue("infrastructure.menu_level_2", Scope.Session);
		}
	}
}
